﻿Public Class Frm_Rech_Avoc_mokhabara

    Private Sub Frm_Rech_Avoc_mokhabara_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

        Frm_Avoc_mokhabara.Enabled = True
        Frm_idafat_mokhabara.Enabled = True
        Frm_Mohami_mokhabara.Enabled = True

    End Sub

    Private Sub Frm_Rech_Avoc_mokhabara_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "الرقم المهني" Then

                For Each av As Avocat_mokhabara In Partager.moi.List_mokhabara
                    If av.Num_Prof.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_Prof, av.Nom_a, av.Prenom_a}))

                    End If

                Next

   ElseIf comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then

                For Each av As Avocat_mokhabara In Partager.moi.List_mokhabara
                    If av.Nom_a.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_Prof, av.Nom_a, av.Prenom_a}))
                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Avocat_mokhabara In Partager.moi.List_mokhabara
                    If av.Prenom_a.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_Prof, av.Nom_a, av.Prenom_a}))
                    End If

                Next


            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click
        If List_tous.SelectedIndices.Count > 0 Then

            If Partager.type = "Frm_idafat_mokhabara" Then

                Dim avo As Avocat_mokhabara
                Dim j As Integer = 0
                Try
                    For Each i As Integer In List_tous.SelectedIndices
                        avo = Partager.list_recherch(i)
                        Frm_idafat_mokhabara.Comb_nom_mokhabara.Text = avo.Nom_a & "  " & avo.Prenom_a
                    Next

                    Me.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            ElseIf Partager.type = "Frm_Mohami_mokhabara" Then

                Dim avo As Avocat_mokhabara
                Dim j As Integer = 0
                Try
                    For Each i As Integer In List_tous.SelectedIndices
                        avo = Partager.list_recherch(i)
                        Frm_Mohami_mokhabara.Comb_nom_mokhabara.Text = avo.Nom_a & "  " & avo.Prenom_a
                    Next

                    Me.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Else
                Dim avo As Avocat_mokhabara
                Dim j As Integer = 0
                Try
                    For Each i As Integer In List_tous.SelectedIndices
                        avo = Partager.list_recherch(i)
                        For Each khib As Avocat_mokhabara In Partager.moi.List_mokhabara
                            If avo.Id = khib.Id Then
                                Frm_Avoc_mokhabara.List_tous.Items(j).Focused = True
                                Frm_Avoc_mokhabara.List_tous.Items(j).Selected = True
                            End If
                            j += 1
                        Next
                    Next
                    Me.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If

        Else
            MsgBox("اختر محامي من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
        Partager.type = ""
    End Sub

End Class